/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package gui;

import controlacciones.ejb3.entity.TbAccion;
import controlacciones.ejb3.pojo.TableBeanBinding_DatosAccionesAprobar;
import delegate.GestionDelegate;
import helper.JP_Utiles_PanelModelo;
import helper.JP_Utiles_PanelBotonesMantenimiento;
import java.awt.BorderLayout;
import org.jdesktop.application.Task;
import java.util.ArrayList;

/**
 *
 * @author Vanessa
 */
public class JP_DetalleAccion extends JP_Utiles_PanelModelo {
    

    /** Creates new form JP_RegistraAccion */
    public JP_DetalleAccion( TableBeanBinding_DatosAccionesAprobar tableBeanBinding_DatosAccionesAprobar) {
        this.tableBeanBinding_DatosAccionesAprobar = tableBeanBinding_DatosAccionesAprobar;
        inicializaComponentes();
    }

    private void inicializaComponentes(){
        initComponents();
        //Panel de Operaciones
        ArrayList alBotones = new ArrayList( 1 );        
        alBotones.add( new Integer( JP_Utiles_PanelBotonesMantenimiento.BOTON_GUARDAR ) );
        alBotones.add( new Integer( JP_Utiles_PanelBotonesMantenimiento.BOTON_DESHACER ) );
        alBotones.add( new Integer( JP_Utiles_PanelBotonesMantenimiento.BOTON_CERRAR ) );

        jp_ope = new JP_Utiles_PanelBotonesMantenimiento( this, alBotones );
        jp_Operaciones.setLayout( new BorderLayout() );
        jp_Operaciones.add( jp_ope, BorderLayout.CENTER );          

        try{
            cargaComboArea();
            cargaComboTipoAccion();
            cargaComboTbClasificacionAccion();            
            inicializarBotones();            
        }catch( Exception ex ){
            System.out.println( "Error en la inicialiacion: " + ex.getMessage() );
        }
        
    }   

    public void setDatos( TableBeanBinding_DatosAccionesAprobar t ){
        try{
            TbAccion tbAccion = GestionDelegate.getInstance().buscarAccion( t.getIdAccion() );
            //TbAccion
            this.idAccionField.setText( tbAccion.getIdAccion() + "" );
            this.FechaRegistroField.setText( tbAccion.getFechaRegistro()+ "");
            this.cmbArea.setSelectedItem( tbAccion.getTbTipoAccionClasificacionAccionArea().getTbArea() );
            this.cmbTipoAccion.setSelectedItem( tbAccion.getTbTipoAccionClasificacionAccionArea().getTbTipoAccion() );
            this.cmbClasificacionAccion.setSelectedItem( tbAccion.getTbTipoAccionClasificacionAccionArea().getTbClasificacionAccion() );
            //TbCliente
            this.NumInscripField.setText( t.getNumInscrip() );
            this.NombreField.setText( t.getNombre() );
            this.DireccionField.setText(t.getDireccion());

        }catch( Exception ex ){
            System.out.println( "Error en setDatos: " + ex.getMessage() );
        }
    }

    public void inicializaReferencias(){
    }

    private void cargaComboArea(  ){
        new helper.Utiles_Combo().cargaComboArea(comboBeanBindingArea1, bindingGroup, cmbArea);
    }

    public void cargaComboTipoAccion(){
        new helper.Utiles_Combo().cargaComboTipoAccion(comboBeanBindingTbTipoAccion1, bindingGroup, cmbTipoAccion);
    }

    public void cargaComboTbClasificacionAccion(){
        new helper.Utiles_Combo().cargaComboTbClasificacionAccion(comboBeanBindingTbClasificacionAccion1, bindingGroup, cmbClasificacionAccion);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always re-generated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        comboBeanBindingArea1 = new beansbinding.ComboBeanBindingArea();
        comboBeanBindingTbClasificacionAccion1 = new beansbinding.ComboBeanBindingTbClasificacionAccion();
        comboBeanBindingTbTipoAccion1 = new beansbinding.ComboBeanBindingTbTipoAccion();
        jp_Operaciones = new javax.swing.JPanel();
        jp_DatosUsuario = new javax.swing.JPanel();
        idAccionField = new javax.swing.JTextField();
        codTipoAccionLabel = new javax.swing.JLabel();
        cmbClasificacionAccion = new javax.swing.JComboBox();
        cmbTipoAccion = new javax.swing.JComboBox();
        cmbArea = new javax.swing.JComboBox();
        codCatAccionLabel = new javax.swing.JLabel();
        AreaLabel = new javax.swing.JLabel();
        tiempoRptaLimiteLabel1 = new javax.swing.JLabel();
        codTipoAccionLabel1 = new javax.swing.JLabel();
        FechaRegistroField = new javax.swing.JTextField();
        codTipoAccionLabel3 = new javax.swing.JLabel();
        NumInscripField = new javax.swing.JTextField();
        codTipoAccionLabel4 = new javax.swing.JLabel();
        NombreField = new javax.swing.JTextField();
        codTipoAccionLabel5 = new javax.swing.JLabel();
        DireccionField = new javax.swing.JTextField();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(controlaccionescomercial.ControlAccionesComercialApp.class).getContext().getResourceMap(JP_DetalleAccion.class);
        jp_Operaciones.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jp_Operaciones.border.title"))); // NOI18N
        jp_Operaciones.setName("jp_Operaciones"); // NOI18N

        javax.swing.GroupLayout jp_OperacionesLayout = new javax.swing.GroupLayout(jp_Operaciones);
        jp_Operaciones.setLayout(jp_OperacionesLayout);
        jp_OperacionesLayout.setHorizontalGroup(
            jp_OperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 522, Short.MAX_VALUE)
        );
        jp_OperacionesLayout.setVerticalGroup(
            jp_OperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 40, Short.MAX_VALUE)
        );

        jp_DatosUsuario.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jp_DatosUsuario.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jp_DatosUsuario.border.titleFont"))); // NOI18N
        jp_DatosUsuario.setName("jp_DatosUsuario"); // NOI18N

        idAccionField.setEnabled(false);
        idAccionField.setName("idAccionField"); // NOI18N

        codTipoAccionLabel.setText(resourceMap.getString("codTipoAccionLabel.text")); // NOI18N
        codTipoAccionLabel.setName("codTipoAccionLabel"); // NOI18N

        cmbClasificacionAccion.setEnabled(false);
        cmbClasificacionAccion.setName("cmbClasificacionAccion"); // NOI18N

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, comboBeanBindingTbClasificacionAccion1, eLProperty, cmbClasificacionAccion);
        bindingGroup.addBinding(jComboBoxBinding);

        cmbClasificacionAccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                cmbClasificacionAccionKeyPressed(evt);
            }
        });

        cmbTipoAccion.setEnabled(false);
        cmbTipoAccion.setName("cmbTipoAccion"); // NOI18N

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, comboBeanBindingTbTipoAccion1, eLProperty, cmbTipoAccion);
        bindingGroup.addBinding(jComboBoxBinding);

        cmbTipoAccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbTipoAccionActionPerformed(evt);
            }
        });

        cmbArea.setEnabled(false);
        cmbArea.setName("cmbArea"); // NOI18N

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, comboBeanBindingArea1, eLProperty, cmbArea);
        bindingGroup.addBinding(jComboBoxBinding);

        cmbArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbAreaActionPerformed(evt);
            }
        });

        codCatAccionLabel.setText(resourceMap.getString("codCatAccionLabel.text")); // NOI18N
        codCatAccionLabel.setName("codCatAccionLabel"); // NOI18N

        AreaLabel.setText(resourceMap.getString("AreaLabel.text")); // NOI18N
        AreaLabel.setName("AreaLabel"); // NOI18N

        tiempoRptaLimiteLabel1.setText(resourceMap.getString("tiempoRptaLimiteLabel1.text")); // NOI18N
        tiempoRptaLimiteLabel1.setName("tiempoRptaLimiteLabel1"); // NOI18N

        codTipoAccionLabel1.setText(resourceMap.getString("codTipoAccionLabel1.text")); // NOI18N
        codTipoAccionLabel1.setName("codTipoAccionLabel1"); // NOI18N

        FechaRegistroField.setEnabled(false);
        FechaRegistroField.setName("FechaRegistroField"); // NOI18N

        codTipoAccionLabel3.setText(resourceMap.getString("codTipoAccionLabel3.text")); // NOI18N
        codTipoAccionLabel3.setName("codTipoAccionLabel3"); // NOI18N

        NumInscripField.setEnabled(false);
        NumInscripField.setName("NumInscripField"); // NOI18N

        codTipoAccionLabel4.setText(resourceMap.getString("codTipoAccionLabel4.text")); // NOI18N
        codTipoAccionLabel4.setName("codTipoAccionLabel4"); // NOI18N

        NombreField.setEnabled(false);
        NombreField.setName("NombreField"); // NOI18N

        codTipoAccionLabel5.setText(resourceMap.getString("codTipoAccionLabel5.text")); // NOI18N
        codTipoAccionLabel5.setName("codTipoAccionLabel5"); // NOI18N

        DireccionField.setEnabled(false);
        DireccionField.setName("DireccionField"); // NOI18N

        javax.swing.GroupLayout jp_DatosUsuarioLayout = new javax.swing.GroupLayout(jp_DatosUsuario);
        jp_DatosUsuario.setLayout(jp_DatosUsuarioLayout);
        jp_DatosUsuarioLayout.setHorizontalGroup(
            jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_DatosUsuarioLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp_DatosUsuarioLayout.createSequentialGroup()
                        .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(codTipoAccionLabel)
                            .addComponent(codTipoAccionLabel1))
                        .addGap(82, 82, 82)
                        .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(idAccionField)
                            .addComponent(FechaRegistroField, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)))
                    .addGroup(jp_DatosUsuarioLayout.createSequentialGroup()
                        .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(codCatAccionLabel)
                            .addComponent(tiempoRptaLimiteLabel1)
                            .addComponent(AreaLabel)
                            .addComponent(codTipoAccionLabel3)
                            .addComponent(codTipoAccionLabel4)
                            .addComponent(codTipoAccionLabel5))
                        .addGap(21, 21, 21)
                        .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(NumInscripField, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cmbTipoAccion, javax.swing.GroupLayout.Alignment.TRAILING, 0, 363, Short.MAX_VALUE)
                            .addComponent(cmbClasificacionAccion, 0, 363, Short.MAX_VALUE)
                            .addComponent(cmbArea, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(NombreField, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
                            .addComponent(DireccionField, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jp_DatosUsuarioLayout.setVerticalGroup(
            jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp_DatosUsuarioLayout.createSequentialGroup()
                .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codTipoAccionLabel)
                    .addComponent(idAccionField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codTipoAccionLabel1)
                    .addComponent(FechaRegistroField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(AreaLabel)
                    .addComponent(cmbArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbTipoAccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tiempoRptaLimiteLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codCatAccionLabel)
                    .addComponent(cmbClasificacionAccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codTipoAccionLabel3)
                    .addComponent(NumInscripField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codTipoAccionLabel4)
                    .addComponent(NombreField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jp_DatosUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codTipoAccionLabel5)
                    .addComponent(DireccionField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jp_Operaciones, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jp_DatosUsuario, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jp_DatosUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jp_Operaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbClasificacionAccionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cmbClasificacionAccionKeyPressed
        if(evt.getKeyCode()== evt.VK_ENTER){
            this.jp_ope.getBtnGuardar().requestFocus();
        }
}//GEN-LAST:event_cmbClasificacionAccionKeyPressed

    private void cmbTipoAccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTipoAccionActionPerformed

}//GEN-LAST:event_cmbTipoAccionActionPerformed

    private void cmbAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbAreaActionPerformed

}//GEN-LAST:event_cmbAreaActionPerformed

    private void limpiarComponentes(){
        this.cmbArea.setSelectedIndex( -1 );
        this.cmbClasificacionAccion.setSelectedIndex( -1 );
        this.cmbTipoAccion.setSelectedIndex( -1 );
        this.idAccionField.setText( "" );
        this.FechaRegistroField.setText( "" );
    }

    private void habilitarBotones( boolean ban ){
        jp_ope.getBtnGuardar().setEnabled( ban );
        jp_ope.getBtnDeshacer().setEnabled( ban);
        jp_ope.getBtnCerrar().setEnabled( !ban );
    }

    @Override
    public Task cerrar() {
        this.cerrarPadre();
        return null;
    }

    private void inicializarBotones(){
        jp_ope.getBtnGuardar().setEnabled( false );
        jp_ope.getBtnDeshacer().setEnabled( false );
        jp_ope.getBtnCerrar().setEnabled( true );
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel AreaLabel;
    private javax.swing.JTextField DireccionField;
    private javax.swing.JTextField FechaRegistroField;
    private javax.swing.JTextField NombreField;
    private javax.swing.JTextField NumInscripField;
    private javax.swing.JComboBox cmbArea;
    private javax.swing.JComboBox cmbClasificacionAccion;
    private javax.swing.JComboBox cmbTipoAccion;
    private javax.swing.JLabel codCatAccionLabel;
    private javax.swing.JLabel codTipoAccionLabel;
    private javax.swing.JLabel codTipoAccionLabel1;
    private javax.swing.JLabel codTipoAccionLabel3;
    private javax.swing.JLabel codTipoAccionLabel4;
    private javax.swing.JLabel codTipoAccionLabel5;
    private beansbinding.ComboBeanBindingArea comboBeanBindingArea1;
    private beansbinding.ComboBeanBindingTbClasificacionAccion comboBeanBindingTbClasificacionAccion1;
    private beansbinding.ComboBeanBindingTbTipoAccion comboBeanBindingTbTipoAccion1;
    private javax.swing.JTextField idAccionField;
    private javax.swing.JPanel jp_DatosUsuario;
    private javax.swing.JPanel jp_Operaciones;
    private javax.swing.JLabel tiempoRptaLimiteLabel1;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    private JP_Utiles_PanelBotonesMantenimiento jp_ope;
    
    TableBeanBinding_DatosAccionesAprobar  tableBeanBinding_DatosAccionesAprobar ;
    //javax.swing.text.MaskFormatter mascara;
}
